package cn.project;

import cn.project.dao.UserTempDao;
import cn.project.model.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class test2 {
    /*
* 利用jdbc模板进行查询所有
* */
    @Test
    public void demo4(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserTempDao userTempDao=ac.getBean("userTemDao", UserTempDao.class);
        List<User> list=userTempDao.getAllUser();
        for (User user :list) {
            System.out.println(user.getUserid()+","+user.getUsername());
        }
    }
    @Test
    public void demo3(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserTempDao userTempDao=ac.getBean("NamedParameter", UserTempDao.class);
        User user=new User();
        user.setUsername("小李飞刀");
        user.setPassword("123");
        userTempDao.save(user);
    }
    @Test
    public void demo6(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserTempDao userTempDao=ac.getBean("NamedParameter", UserTempDao.class);
        User user=userTempDao.findById(5);
        System.out.println(user.getUserid()+","+user.getUsername());

    }
    @Test
    public void demo7(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserTempDao userTempDao=ac.getBean("NamedParameter", UserTempDao.class);
        User us=new User();
        us.setUsername("二郎神");
        us.setUserid(1);
        int m=userTempDao.update(us);
        System.out.println(m);
    }
}
